from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-23 14:02:35.296952
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 23, Aug, 2022
Time: 14:02:40
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1991
Nobs: 757.000 HQIC: -50.5375
Log likelihood: 9631.44 FPE: 9.11579e-23
AIC: -50.7495 Det(Omega_mle): 8.10026e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296383 0.055098 5.379 0.000
L1.Burgenland 0.107656 0.036592 2.942 0.003
L1.Kärnten -0.106846 0.019421 -5.501 0.000
L1.Niederösterreich 0.208791 0.076407 2.733 0.006
L1.Oberösterreich 0.107104 0.074298 1.442 0.149
L1.Salzburg 0.254053 0.039132 6.492 0.000
L1.Steiermark 0.037377 0.051039 0.732 0.464
L1.Tirol 0.108216 0.041351 2.617 0.009
L1.Vorarlberg -0.060392 0.035517 -1.700 0.089
L1.Wien 0.052437 0.065996 0.795 0.427
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062903 0.114575 0.549 0.583
L1.Burgenland -0.033407 0.076093 -0.439 0.661
L1.Kärnten 0.046997 0.040386 1.164 0.245
L1.Niederösterreich -0.175405 0.158886 -1.104 0.270
L1.Oberösterreich 0.400005 0.154501 2.589 0.010
L1.Salzburg 0.288628 0.081374 3.547 0.000
L1.Steiermark 0.106189 0.106135 1.001 0.317
L1.Tirol 0.314106 0.085988 3.653 0.000
L1.Vorarlberg 0.026297 0.073857 0.356 0.722
L1.Wien -0.028670 0.137237 -0.209 0.835
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189823 0.028282 6.712 0.000
L1.Burgenland 0.090089 0.018783 4.796 0.000
L1.Kärnten -0.008848 0.009969 -0.888 0.375
L1.Niederösterreich 0.260217 0.039220 6.635 0.000
L1.Oberösterreich 0.134617 0.038138 3.530 0.000
L1.Salzburg 0.045745 0.020087 2.277 0.023
L1.Steiermark 0.018625 0.026199 0.711 0.477
L1.Tirol 0.093739 0.021226 4.416 0.000
L1.Vorarlberg 0.058249 0.018231 3.195 0.001
L1.Wien 0.118938 0.033877 3.511 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107455 0.028770 3.735 0.000
L1.Burgenland 0.046605 0.019107 2.439 0.015
L1.Kärnten -0.014384 0.010141 -1.418 0.156
L1.Niederösterreich 0.191825 0.039896 4.808 0.000
L1.Oberösterreich 0.292532 0.038795 7.540 0.000
L1.Salzburg 0.111223 0.020433 5.443 0.000
L1.Steiermark 0.102738 0.026650 3.855 0.000
L1.Tirol 0.108851 0.021592 5.041 0.000
L1.Vorarlberg 0.069909 0.018545 3.770 0.000
L1.Wien -0.017506 0.034460 -0.508 0.611
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128244 0.052206 2.456 0.014
L1.Burgenland -0.050598 0.034672 -1.459 0.144
L1.Kärnten -0.040582 0.018402 -2.205 0.027
L1.Niederösterreich 0.171329 0.072397 2.367 0.018
L1.Oberösterreich 0.139464 0.070399 1.981 0.048
L1.Salzburg 0.288433 0.037079 7.779 0.000
L1.Steiermark 0.033821 0.048361 0.699 0.484
L1.Tirol 0.162336 0.039181 4.143 0.000
L1.Vorarlberg 0.100579 0.033653 2.989 0.003
L1.Wien 0.069079 0.062533 1.105 0.269
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056852 0.041648 1.365 0.172
L1.Burgenland 0.040572 0.027660 1.467 0.142
L1.Kärnten 0.050322 0.014680 3.428 0.001
L1.Niederösterreich 0.220414 0.057755 3.816 0.000
L1.Oberösterreich 0.285942 0.056162 5.091 0.000
L1.Salzburg 0.045111 0.029580 1.525 0.127
L1.Steiermark -0.001029 0.038580 -0.027 0.979
L1.Tirol 0.147192 0.031257 4.709 0.000
L1.Vorarlberg 0.072567 0.026847 2.703 0.007
L1.Wien 0.082971 0.049886 1.663 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.177752 0.049752 3.573 0.000
L1.Burgenland -0.003400 0.033042 -0.103 0.918
L1.Kärnten -0.062061 0.017537 -3.539 0.000
L1.Niederösterreich -0.080305 0.068994 -1.164 0.244
L1.Oberösterreich 0.192866 0.067089 2.875 0.004
L1.Salzburg 0.057320 0.035335 1.622 0.105
L1.Steiermark 0.231897 0.046087 5.032 0.000
L1.Tirol 0.495990 0.037339 13.283 0.000
L1.Vorarlberg 0.046791 0.032071 1.459 0.145
L1.Wien -0.054479 0.059593 -0.914 0.361
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165574 0.057267 2.891 0.004
L1.Burgenland -0.010716 0.038033 -0.282 0.778
L1.Kärnten 0.067133 0.020186 3.326 0.001
L1.Niederösterreich 0.205881 0.079415 2.592 0.010
L1.Oberösterreich -0.068379 0.077223 -0.885 0.376
L1.Salzburg 0.210747 0.040672 5.182 0.000
L1.Steiermark 0.116677 0.053049 2.199 0.028
L1.Tirol 0.070931 0.042979 1.650 0.099
L1.Vorarlberg 0.121800 0.036915 3.299 0.001
L1.Wien 0.122034 0.068594 1.779 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360168 0.032911 10.944 0.000
L1.Burgenland 0.007389 0.021857 0.338 0.735
L1.Kärnten -0.023604 0.011601 -2.035 0.042
L1.Niederösterreich 0.214466 0.045639 4.699 0.000
L1.Oberösterreich 0.193999 0.044380 4.371 0.000
L1.Salzburg 0.044884 0.023374 1.920 0.055
L1.Steiermark -0.015466 0.030487 -0.507 0.612
L1.Tirol 0.105698 0.024700 4.279 0.000
L1.Vorarlberg 0.072807 0.021215 3.432 0.001
L1.Wien 0.041527 0.039421 1.053 0.292
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040183 0.146699 0.192990 0.156180 0.124325 0.110152 0.065411 0.221974
Kärnten 0.040183 1.000000 -0.005471 0.133149 0.039907 0.095364 0.431281 -0.053077 0.098651
Niederösterreich 0.146699 -0.005471 1.000000 0.336934 0.145953 0.298872 0.103005 0.181391 0.318381
Oberösterreich 0.192990 0.133149 0.336934 1.000000 0.227454 0.330858 0.173598 0.167030 0.263658
Salzburg 0.156180 0.039907 0.145953 0.227454 1.000000 0.146701 0.118480 0.145983 0.127208
Steiermark 0.124325 0.095364 0.298872 0.330858 0.146701 1.000000 0.150619 0.137247 0.077422
Tirol 0.110152 0.431281 0.103005 0.173598 0.118480 0.150619 1.000000 0.113779 0.147798
Vorarlberg 0.065411 -0.053077 0.181391 0.167030 0.145983 0.137247 0.113779 1.000000 0.003689
Wien 0.221974 0.098651 0.318381 0.263658 0.127208 0.077422 0.147798 0.003689 1.000000